<template>

  <basic-container>
    <avue-form :option="option"
               v-model="form"
               @submit="handleSubmit"
    ></avue-form>

  </basic-container>
</template>

<script>
import {baseUrl} from "../../../config/env";
import iconList from "@/config/iconList";
import baseService from "../../../crud/baseService";

export default {
  name: "createMenu",
  data() {
    return {
      tableId: "",
      form: {
        parentId: -1,
        name: "",
        icon: "",
        path: ""
      },

      option: {
        column: [
          {
            label: '菜单名称',
            prop: 'name',
            rules: [{
              required: true,
              message: "请输入菜单名称",
              trigger: "blur"
            }]
          },
          {
            label: '父菜单',
            prop: 'parentId',
            type: 'tree',
            dicUrl: baseUrl + '/system/sysMenu/allTree',
            props: {
              label: 'name',
              value: 'id'
            },
            rules: [{
              required: true,
              message: "请选择父菜单",
              trigger: "blur"
            }]
          },
          {
            label: '路径',
            prop: 'path',
            rules: [{
              required: true,
              message: "请输入路径",
              trigger: "blur"
            }]
          },
          {
            label: '图标选择器',
            prop: 'icon',
            type: 'icon',


            minRows: 6,
            iconList: iconList,
            display: true,
            rules: [{
              required: true,
              message: "请选择图标",
              trigger: "blur"
            }]
          },
        ],

      }
    }
  }, methods: {
    init(row, item) {
      this.form.name = row.tableComment
      this.form.path = row.moduleName + "/" + row.entityName
      this.tableId = row.id;


    },
    handleSubmit(form, done) {

      baseService.postJsonData("/generator/gTableInfo/createMenu/" + this.tableId, form).then(res => {
        if (res.status != 200) {

          this.$message.error(res.msg);
        } else {
          this.$message.success("保存成功");
          // return
          this.$nextTick(() => {
            setTimeout(() => {
              this.$emit("updateDialogVisible", false)
            }, 200)
          });
        }
      });
    }

  }
}
</script>


<style scoped>

</style>
